package org.anderground.editor.gui.properties.transfer;

import java.util.ArrayList;
import java.util.List;

import org.anderground.core.model.Station;
import org.anderground.core.model.Transfer;
import org.anderground.core.model.Tunnel;
import org.anderground.editor.gui.properties.AbstractPropertiesPanel;

@SuppressWarnings("serial")
public class TransferPropertiesPanel extends AbstractPropertiesPanel<Transfer> {

	private Transfer[] transfers;

	public TransferPropertiesPanel() {
		super(new TransferFromStationNameProperty(),
				new TransferToStationNameProperty(), new TransferTimeProperty());
	}

	@Override
	public void onSelectionChanged(List<Station> selectedStations,
			List<Tunnel> selectedTunnel) {
		List<Transfer> temp = new ArrayList<Transfer>();
		for (Station s : selectedStations) {
			temp.addAll(s.getTransfers());
		}
		transfers = temp.toArray(new Transfer[0]);
		this.updateView();
	}

	@Override
	protected int getRowCount() {
		return (transfers == null) ? 0 : transfers.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return (transfers == null || rowIndex < 0 || rowIndex >= transfers.length) ? null
				: transfers[rowIndex];
	}

}
